using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Data.Common;
using System.Data;
using System.Collections;
using Oracle.DataAccess.Client;

namespace LinqGen
{
	internal sealed class DataTool
	{
		#region Fields

		private static string owner = ConfigurationManager.AppSettings["DatabaseOwner"] as string;

		#endregion

		#region Constructors

		public DataTool()
		{
		}

		#endregion

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static IDataReader GetAllTables()
		{
			OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["LinqGenConnectionString"].ConnectionString);

			try
			{
				connection.Open();
				
				string commandText = string.Format(Resources.OracleQueries.SelectAllTables, owner);
				using (OracleCommand command= new OracleCommand(commandText, connection))
				{
					return command.ExecuteReader(CommandBehavior.CloseConnection);
				}
			}
			catch
			{
				if (connection.State == ConnectionState.Open)
				{
					connection.Close();
				}
				throw;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="dataType"></param>
		/// <returns></returns>
		public static bool IsNumericType(string dataType)
		{
			bool result =
				dataType.StartsWith("VARCHAR", StringComparison.InvariantCultureIgnoreCase) ||
				dataType.StartsWith("NVARCHAR", StringComparison.InvariantCultureIgnoreCase) ||
				dataType.StartsWith("DATE", StringComparison.InvariantCultureIgnoreCase) ||
				dataType.StartsWith("TIME", StringComparison.InvariantCultureIgnoreCase);
			return !result;
		}
	}

}
